home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / GMS / Source / C / Blitter / BlitWorm.c next >
Encoding:
C/C++ Source or Header  |  1997-05-04  |  3.5 KB  |  158 lines

  1. /* Bob Demo
  2. ** --------
  3. ** Blits a Worm to screen using a bob structure.  This version does not
  4. ** include the sound from the assembler version.
  5. **
  6. ** To compile with SAS/C:
  7. **
  8. **    1> sc BlitWorm.c link startup=LIB:gms.o data=far
  9. **
  10. */
  11.  
  12. #include <proto/games.h>
  13.  
  14. extern struct GMSBase *GMSBase;
  15. ULONG _XCEXIT = NULL;
  16. ULONG PREFSNAME = DEFAULT;
  17.  
  18. struct GameScreen *GameScreen;
  19. struct Restorelist *Restorelist;
  20. struct Bob *BOB_Worm;
  21.  
  22. #define TRUE 1
  23. #define FALSE 0
  24.  
  25. void Demo(void);
  26.  
  27. void main(void) {
  28.   struct Picture *PIC_Bobs;
  29.   struct Picture *PIC_Background;
  30.  
  31.   WORD WormFrames[] = {
  32.       0,0,0,0,  32,0,0,0,  64,0,0,0,  96,0,0,0,
  33.     128,0,0,0, 160,0,0,0, 192,0,0,0, 224,0,0,0,
  34.     256,0,0,0, 288,0,0,0,  0,48,0,0, 32,48,0,0,
  35.     64,48,0,0,
  36.     -1
  37.   };
  38.  
  39.   if (AllocBlitter() == ERR_OK) {
  40.    if (AllocAudio() == ERR_OK) {
  41.     if (GameScreen = AddScreenTags(TAGS_GAMESCREEN,NULL,
  42.         GSA_Planes,5,
  43.         GSA_ScrWidth,320,
  44.         GSA_ScrHeight,256,
  45.         GSA_Attrib,DBLBUFFER,
  46.         TAGEND)) {
  47.  
  48.      if (PIC_Background = LoadPicTags(TAGS_PICTURE,NULL,
  49.         PCA_Data,GameScreen->MemPtr2,
  50.         PCA_Width,GameScreen->PicWidth,
  51.         PCA_Height,GameScreen->PicHeight,
  52.         PCA_Planes,GameScreen->Planes,
  53.         PCA_ScrMode,GameScreen->ScrMode,
  54.         PCA_ScrType,GameScreen->ScrType,
  55.         PCA_Options,GETPALETTE,
  56.         PCA_File,"GMS:demos/data/PIC.Green",
  57.         TAGEND)) {
  58.  
  59.       GameScreen->Palette = PIC_Background->Palette; 
  60.       UpdatePalette(GameScreen);
  61.       SwapBuffers(GameScreen);
  62.       CopyBuffer(GameScreen,BUFFER1,BUFFER2);
  63.  
  64.       if (Restorelist = InitRestore(2,1)) {
  65.  
  66.        if (PIC_Bobs = LoadPicTags(TAGS_PICTURE,NULL,
  67.           PCA_Planes,GameScreen->Planes,
  68.           PCA_ScrType,GameScreen->ScrType,
  69.           PCA_Options,VIDEOMEM,
  70.           PCA_File,"GMS:demos/data/PIC.Rambo",
  71.           TAGEND)) {
  72.  
  73.         if (BOB_Worm = InitBobTags(GameScreen,TAGS_BOB,NULL,
  74.            BBA_Framelist,WormFrames,
  75.            BBA_Width,32,
  76.            BBA_Height,24,
  77.            BBA_XCoord,150,
  78.            BBA_YCoord,150,
  79.            BBA_Attrib,RESTORE|GENMASKS|CLIP,
  80.            BBA_PictureTags,PIC_Bobs,
  81.            TAGEND)) {
  82.  
  83.           ShowScreen(GameScreen); 
  84.           Demo();
  85.  
  86.         FreeBob(BOB_Worm); 
  87.         }
  88.        FreePic(PIC_Bobs); 
  89.        }
  90.       FreeRestore(Restorelist); 
  91.       }
  92.      FreePic(PIC_Background); 
  93.      }
  94.     DeleteScreen(GameScreen); 
  95.     }
  96.    FreeAudio(); 
  97.    }
  98.   FreeBlitter(); 
  99.   }
  100. }
  101.  
  102. /*=========================================================================*/
  103.  
  104. void Demo(void)
  105. {
  106.   ULONG mouse=0; 
  107.   UWORD anim=0,fire=FALSE;
  108.  
  109.   InitJoyPorts(); 
  110.  
  111.   do
  112.   {
  113.     Restore(GameScreen,Restorelist); 
  114.     DrawBob(GameScreen,BOB_Worm,BUFFER2,Restorelist); 
  115.     WaitVBL(); 
  116.     SwapBuffers(GameScreen);
  117.  
  118.     /* Animate the Worm's movements */
  119.  
  120.     anim++;
  121.  
  122.     if (fire == FALSE) {
  123.       if (anim > 5) {
  124.         anim = 0;
  125.         BOB_Worm->Frame++;
  126.         if (BOB_Worm->Frame > 9)
  127.            BOB_Worm->Frame = 0;
  128.       }
  129.     }
  130.     else if (anim > 1) {
  131.       anim = 0;
  132.       if (BOB_Worm->Frame < 10)
  133.          BOB_Worm->Frame = 9;
  134.  
  135.       BOB_Worm->Frame++;
  136.  
  137.       if (BOB_Worm->Frame > 12) {
  138.          if (mouse & MB_LMB)
  139.             BOB_Worm->Frame = 11;
  140.          else {
  141.             BOB_Worm->Frame = 0;
  142.             fire = FALSE;
  143.          }
  144.       }
  145.     }
  146.  
  147.     /* Get the user input */
  148.  
  149.     mouse = ReadJoyPort(JPORT1,JT_ZBXY);
  150.     BOB_Worm->XCoord += GetX(mouse);
  151.     BOB_Worm->YCoord += GetY(mouse);
  152.     if (mouse & MB_LMB)
  153.        fire = TRUE;
  154.  
  155.   } while (!(mouse & MB_RMB)); 
  156. }
  157.  
  158.